package com.learning.servlet2x.skip;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * ClassName: RedirectServlet
 * Description: 重定向 Servlet
 * Date: 2018/6/23 14:11 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class RedirectServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("param", "request_param");

        // 重定向到页面
        resp.setStatus(301);
        resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        resp.setHeader("Location", req.getContextPath() + "/requestServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect(req.getContextPath() + "/requestServlet");
    }
}
